<?php
//ini_set('max_execution_time', '120');
//set_time_limit(0);

// mod文件只能被入口文件引用，不能直接访问
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}


//if(!$_G['uid']) {
	//showmessage('抱歉，您尚未登录，无法进行此操作', '', array(), array('login' => 1));
//}

$s_url = $_REQUEST['s_url'];
//echo $s_url;
preg_match('/[a-zA-z]+:\/\/([^\/]+)\//i', $s_url, $match);

$host = $match[1];

$do = str_replace('.','',$host);

$checkArray = array(
    'ilaoyoucn' => 'wwwilaoyoucn'
);

$do = isset($checkArray[$do]) ? $checkArray[$do] : $do;
$do2=fxurl($s_url);

//$doarray = array('ilaoyou','gxsky');

// 判断 $mod 的合法性
///$do = !in_array($do, $doarray) ? 'index' : $do;

if(is_file(DISCUZ_ROOT."/source/class/collect/".'collect_'.$do.".php")){
	$pageinfo = call_user_func('collect_'.$do.'::getPageContent', $s_url);
}else if($do2!=""&&is_file(DISCUZ_ROOT."/source/class/collect/".'collect_'.$do2.".php")){
    $pageinfo = call_user_func('collect_'.$do2.'::getPageContent', $s_url);
}


//echo trim($pageinfo['message']);exit;
if(trim($pageinfo['message'])==""){
	require_once(APP_PATH . "Common/yzs1013_pldr.php");
    require_once(DISCUZ_ROOT."/source/class/collect/zqnews.class.php");
	$pageinfo = call_user_func('collect_tongyong::getPageContent', $s_url,$_GET['gather_type']);
	//if(preg_match("/bug/Uisx",$s_url)) print_r($pageinfo);
}


//require_once libfile('misc/forumselect', 'include');
//记录采集日志
$remote_ip = GetRemoteIp();
$site_url = $_REQUEST['site_url'];	
$html = "[".date('Y-m-d H:i:s', time())."]  ".$site_url."  ".$remote_ip."  ".$s_url."\r\n";
file_put_contents(DISCUZ_ROOT."/data/collect_logs.txt",$html,FILE_APPEND);
		

$data = array(
    'subject' => $pageinfo['title'],
    'message' => $pageinfo['message'],
	'from' => $pageinfo['from'],
	'status' => (strlen($pageinfo['message'])<100)?'error':'ok',
	's_url'=>$s_url
);


$json_data = json_encode($data);

if(trim($_REQUEST['request_type']) == 'post'){
	echo $json_data;
}else{
	$callback = $_GET['jsoncallback'];
	echo $callback . '(' . $json_data . ')';
}

function GetRemoteIp($default='127.0.0.1')
{
	$ip_string = $_SERVER['HTTP_CLIENT_IP'].','.$_SERVER['HTTP_X_FORWARDED_FOR'].','.$_SERVER['REMOTE_ADDR'];
	if ( preg_match ("/\d+\.\d+\.\d+\.\d+/", $ip_string, $matches) )
	{
		return $matches[0];
	}
	return $default;
}
function fxurl($url){
  preg_match_all("/http\:\/\/[^<>\/\.]+\.([^<>\/]+)/isx",$url,$nn);
  $host=$nn[1][0];
  switch($host){
    case "qq.com":
        if(preg_match("/p\=/Uisx",$url)||preg_match("/\/a\//Uisx",$url)){
		$return="qqphotolist";
	    }
		break;
    case "163.com":
        if(preg_match("/\/photoview\//Uisx",$url)){
		$return="163photolist";
	    }
		break;
    case "news.sina.com.cn":
        if(preg_match("/\/slide/Uisx",$url)){
		$return="sinaphotolist";
	    }
		break;
    case "eladies.sina.com.cn":
        if(preg_match("/\/slide/Uisx",$url)){
		$return="sinaphotolist";
	    }
		break;
    case "games.sina.com.cn":
        if(preg_match("/\/slide/Uisx",$url)){
		$return="sinaphotolist";
	    }
		break;

    case "hatuwang.com":
        if(preg_match("/\/detaile/Uisx",$url)){
		$return="hatuwangphotolist";
	    }
		break;



  }
  return $return;
}
?>